package main

import "fmt"

func maxProfit(prices []int) int {
	if len(prices) <= 1 {
		return 0
	}

	var sum int
	for i := 1; i < len(prices); i++ {
		if prices[i] > prices[i-1] {
			sum += prices[i] - prices[i-1]
		}
	}
	return sum
}

func main() {
	prices := []int{1, 5, 2, 3, 1}
	fmt.Println(maxProfit(prices))
}
